package com.base.im.server.netty.client;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class ClientServerHandler extends ChannelInboundHandlerAdapter{

	public void channelRead(ChannelHandlerContext ctx, Object msg) {   
        System.out.println(" 客户端收到  :" + msg);
        
        
//        ctx.channel().writeAndFlush(msg);
//        ctx.write(msg);//写回数据，  
        
    }   
    public void channelReadComplete(ChannelHandlerContext ctx) {   
    	ctx.flush();
//        ctx.writeAndFlush(Unpooled.EMPTY_BUFFER); //flush掉所有写回的数据  
//        .addListener(ChannelFutureListener.CLOSE); //当flush完成后关闭channel  
    }   
    public void exceptionCaught(ChannelHandlerContext ctx,Throwable cause) {   
        cause.printStackTrace();//捕捉异常信息  
        ctx.close();//出现异常时关闭channel   
    }     
	
}
